import time
import unittest
from selenium import webdriver

class BaiduSearch(unittest.TestCase) :

    def setUp(self) :
        '''
        测试前的准备
        :return:
        '''
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.implicitly_wait(8)
        self.driver.get("https://www.baidu.com")

    def tearDown(self) :
        '''
        测试后结束 
        :return:
        '''
        #self.driver.quit()

    def test_baidu_search(self) :
        """ 
        这里一定要test开头，把测试逻辑代码封装到一个test开头的方法里。 
        :return: 
        """ 
        self.driver.find_element_by_id('kw').send_keys('selenium')
        time.sleep(2)
        try:
            assert 'selenium' in self.driver.title
            print('Test Pass.')
        except Exception as e:
            print('Test Fail',format(e))
if __name__ =='__main__' :
    unittest.main()